package com.itheima.core.service.product;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.itheima.core.dao.product.ColorDao;
import com.itheima.core.dao.product.SkuDao;
import com.itheima.core.pojo.product.Sku;
import com.itheima.core.pojo.product.SkuQuery;

/**
 * @author zhang.cheng
 *
 *         2017年3月7日
 */
@Service("skuService")
@Transactional
public class SkuServiceImpl implements SkuService {

	@Autowired
	private SkuDao skuDao;

	@Autowired
	private ColorDao colorDao;

	@Override
	public List<Sku> selectSkuList(Long productId) {
		// 通过商品Id查询库存结果集
		SkuQuery skuQuery = new SkuQuery();
		skuQuery.createCriteria().andProductIdEqualTo(productId);
		List<Sku> skuList = skuDao.selectByExample(skuQuery);
		for (Sku sku : skuList) {
			sku.setColor(colorDao.selectByPrimaryKey(sku.getColorId()));
		}
		return skuList;
	}

	@Override
	public void updateSku(Sku sku) {
		skuDao.updateByPrimaryKeySelective(sku);
	}

}
